package com.dkd.manage.controller;

import com.dkd.common.core.domain.R;
import com.dkd.manage.pojo.dto.SkuClassQueryListDto;
import com.dkd.manage.pojo.entity.SkuClass;
import com.dkd.manage.result.PageResult;
import com.dkd.manage.service.SkuClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api(tags = "商品类型管理相关接口")
@RequestMapping("/manage/skuClass")
public class SkuClassController {

    @Autowired
    private SkuClassService skuClassService;

    @ApiOperation("分页查询商品类型列表")
    @PreAuthorize("@ss.hasPermi('manage:skuClass:list')")
    @GetMapping("/list")
    public R<PageResult<SkuClass>> list(SkuClassQueryListDto skuClassQueryListDto) {
        log.info("分页查询商品类型列表：{}", skuClassQueryListDto);
        PageResult<SkuClass> result = skuClassService.list(skuClassQueryListDto);
        return R.ok(result);
    }

    @ApiOperation("新增商品类型")
    @PreAuthorize("@ss.hasPermi('manage:skuClass:add')")
    @PostMapping
    public R<Integer> add(@RequestBody SkuClass skuClass) {
        log.info("新增商品类型：{}", skuClass);
        Integer rows = skuClassService.add(skuClass);
        return R.ok(rows);
    }

    @ApiOperation("根据id查询商品类型")
    @PreAuthorize("@ss.hasPermi('manage:skuClass:query')")
    @GetMapping("/{id}")
    public R<SkuClass> getSkuClassById(@PathVariable Long id) {
        log.info("根据id查询商品类型：{}", id);
        SkuClass skuClass = skuClassService.getSkuClassById(id);
        return R.ok(skuClass);
    }

    @ApiOperation("修改商品类型")
    @PreAuthorize("@ss.hasPermi('manage:skuClass:edit')")
    @PutMapping
    public R<Integer> edit(@RequestBody SkuClass skuClass) {
        log.info("修改商品类型：{}", skuClass);
        Integer rows = skuClassService.edit(skuClass);
        return R.ok(rows);
    }

    @ApiOperation("根据id删除商品类型")
    @PreAuthorize("@ss.hasPermi('manage:skuClass:remove')")
    @DeleteMapping("/{ids}")
    public R<Integer> deleteSkuClassById(@PathVariable Long[] ids) {
        log.info("根据id删除商品类型：{}", ids);
        Integer rows = skuClassService.deleteSkuClassById(ids);
        return R.ok(rows);
    }

}
